package com.binest.invitationFriend.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.binest.common.annotation.Log;
import com.binest.common.core.controller.BaseController;
import com.binest.common.core.domain.AjaxResult;
import com.binest.common.enums.BusinessType;
import com.binest.invitationFriend.domain.InvitationFriend;
import com.binest.invitationFriend.service.IInvitationFriendService;
import com.binest.common.utils.poi.ExcelUtil;
import com.binest.common.core.page.TableDataInfo;

/**
 * 邀请好友Controller
 * 
 * @author wwd
 * @date 2024-02-05
 */
@RestController
@RequestMapping("/invitationFriend")
public class InvitationFriendController extends BaseController
{
    @Autowired
    private IInvitationFriendService invitationFriendService;

    /**
     * 查询邀请好友列表
     */
//    @PreAuthorize("@ss.hasPermi('invitationFriend:invitationFriend:list')")
    @GetMapping("/list")
    public TableDataInfo list(InvitationFriend invitationFriend)
    {
        startPage();
        List<InvitationFriend> list = invitationFriendService.selectInvitationFriendList(invitationFriend);
        return getDataTable(list);
    }

    /**
     * 导出邀请好友列表
     */

    @Log(title = "邀请好友", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InvitationFriend invitationFriend)
    {
        List<InvitationFriend> list = invitationFriendService.selectInvitationFriendList(invitationFriend);
        ExcelUtil<InvitationFriend> util = new ExcelUtil<InvitationFriend>(InvitationFriend.class);
        util.exportExcel(response, list, "邀请好友数据");
    }

    /**
     * 获取邀请好友详细信息
     */

    @GetMapping(value = "/getInfo")
    public AjaxResult getInfo( String id)
    {
        return success(invitationFriendService.selectInvitationFriendById(id));
    }

    /**
     * 新增邀请好友
     */

    @Log(title = "邀请好友", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody InvitationFriend invitationFriend)
    {
        return toAjax(invitationFriendService.insertInvitationFriend(invitationFriend));
    }

    /**
     * 修改邀请好友
     */

    @Log(title = "邀请好友", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody InvitationFriend invitationFriend)
    {
        return toAjax(invitationFriendService.updateInvitationFriend(invitationFriend));
    }

    /**
     * 删除邀请好友
     */

    @Log(title = "邀请好友", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(invitationFriendService.deleteInvitationFriendByIds(ids));
    }
}
